
<link rel="stylesheet" href="lib/jq-module/zyupload/zyupload-1.0.0.min.css" media="all">

<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">

                        <div class="layui-inline">
                            <label class="layui-form-label">开始日期</label>
                            <div class="layui-input-block">
                                <input type="text" name="start" id="start" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">结束日期</label>
                            <div class="layui-input-block">
                                <input type="text" name="end" id="end" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">状态</label>
                            <div class="layui-input-inline">
                                <select name="saleState" lay-verify="" lay-search="">
                                    <option value=""> -所有状态- </option>
                                    <option value="0">下柜</option>
                                    <option value="1">上柜</option>
                                    <option value="2">可上柜</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">商品编码</label>
                            <div class="layui-input-inline">
                                <input type="text" name="wareId" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">商品名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="wareName" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="export"> 导出图片 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="import"> 导入图片 </button>
            </div>
        </script>



        <table class="layui-hide" id="appliesTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>


<script src="lib/jquery-3.4.1/jquery-3.4.1.min.js" charset="utf-8"></script>
<script src="lib/jq-module/zyupload/zyupload-1.0.0.min.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table','miniPage','element', 'util', 'laydate', 'layer', 'upload'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate,
            layer = layui.layer,
            upload = layui.upload;



        form.render();

        laydate.render({
            elem: '#start'
        });

        laydate.render({
            elem: '#end'
        });


        var map = {
            0: "下柜",
            1: "<span style='color: green'>上柜</span>",
            2: "可上柜"
        };

        var map1 = {
            0: "无",
            1: "<span style='color: green'>有</span>"
        };

        var map2 = {
            0: "否",
            1: "是"
        };


        table.render({
            elem: '#appliesTableId',
            url: 'common/productinfos/withoutpic',
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],

            cols: [[
                {type: "checkbox", width: 50},
                {field: 'wareId', width: 180, title: '商品编码'},
                {field: 'wareName', width: 380, title: '商品名称'},
                {field: 'saleState', width: 140, title: '状态', templet: function (d) {
                        return  map[d["saleState"]] || '<span style="color: red">' + d["saleState"] + '</span>';
                    }
                },
                {field: 'modifyTime', title: '审核时间', width: 180, templet : "<div>{{layui.util.toDateString(d.modifyTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
                {field: 'isPrimary', width: 120, title: '主图', templet: function(d) {return  map1[d["isPrimary"]] || '<span style="color: red">' + d["isPrimary"] + '</span>';}},
                {field: 'isGaea', width: 120, title: '盖亚商品', templet: function(d) {return  map2[d["isGaea"]] || '<span style="color: red">' + d["isPrimary"] + '</span>';}},
                {field: 'updateTime', width: 200, title: '更新时间', templet : "<div>{{layui.util.toDateString(d.updateTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('appliesTableId', {
                page: { curr: 1 },
                where:data.field
            }, 'data');

            return false;
        });


        /**
         * toolbar事件监听
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'export') {   // 监听添加操作
                debugger;

                var curWwwPath = window.document.location.href;
                var pathName = window.document.location.pathname;
                var pos = curWwwPath.indexOf(pathName);
                var localhostPath = curWwwPath.substring(0, pos);
                var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
                var url = localhostPath + projectName + "/common/productpic/download";
                window.open(url);

            } else if (obj.event === 'import') {  // 监听删除操作

                function  pop() {
                    var type = 'auto'
                        , text = '111';

                    layer.open({
                        type: 1
                        , area: ['780px', '420px']
                        , offset: type //具体配置参考：http://www.layui.com/doc/modules/layer.html#offset
                        , id: 'layerDemo' + type //防止重复弹出
                        , content: '<div style="padding: 20px 100px;"><div id="zyupload" class="zyupload"></div></div>'
                        , shade: 0 //不显示遮罩
                        , yes: function () {
                            layer.closeAll();
                        }
                        ,success: function(layero){
                            debugger;

                            $("#zyupload").zyUpload({
                                width: "500px",                 // 宽度
                                height: "300px",                 // 宽度
                                itemWidth: "140px",                 // 文件项的宽度
                                itemHeight: "115px",                 // 文件项的高度
                                url: "/common/productpic/upload",  // 上传文件的路径
                                fileType: ["zip"],// 上传文件的类型
                                fileSize: 1024000000,                // 上传文件的大小
                                multiple: false,                    // 是否可以多个文件上传
                                dragDrop: true,                    // 是否可以拖动上传文件
                                tailor: false,                    // 是否可以裁剪图片
                                del: true,                    // 是否可以删除文件
                                finishDel: false,  				  // 是否在上传文件完成后删除预览
                                /* 外部获得的回调接口 */
                                onSelect: function (selectFiles, allFiles) {    // 选择文件的回调方法  selectFile:当前选中的文件  allFiles:还没上传的全部文件
                                    console.info("当前选择了以下文件：");
                                    console.info(selectFiles);
                                },
                                onDelete: function (file, files) {              // 删除一个文件的回调方法 file:当前删除的文件  files:删除之后的文件
                                    console.info("当前删除了此文件：");
                                    console.info(file.name);
                                },
                                onSuccess: function (file, response) {          // 文件上传成功的回调方法
                                    console.info("此文件上传成功：");
                                    console.info(file.name);
                                    console.info("此文件上传到服务器地址：");
                                    console.info(response);
                                    $("#uploadInf").append("<p>上传成功，文件地址是：" + response + "</p>");
                                },
                                onFailure: function (file, response) {          // 文件上传失败的回调方法
                                    console.info("此文件上传失败：");
                                    console.info(file.name);
                                },
                                onComplete: function (response) {           	  // 上传完成的回调方法
                                    console.info("文件上传完成");
                                    console.info(response);
                                }
                            });
                        }
                    });
                }

                pop.call(this);
            }
        });

    });
</script>